package com.twohand.admin.Controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.twohand.admin.Dto.Logindto;
import com.twohand.admin.Dto.MiniLoginRes;
import com.twohand.admin.Entity.User;
import com.twohand.admin.Service.UserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.security.NoSuchAlgorithmException;

@RestController
@RequestMapping("/mini")
public class MiniLoginController {
    @Autowired
    UserService userService;
    @Autowired
    HttpServletRequest httpRequest;
    @ApiOperation("接收小程序的code,查询openid")
    @GetMapping("/login/{code}")
    public MiniLoginRes login(@PathVariable String code) throws JsonProcessingException {
        return userService.miniprogramLogin(code);
    }
    @PostMapping("/login")
    public Object adminLogin(@RequestBody Logindto user) throws NoSuchAlgorithmException {
        return userService.adminLogin(user.getNickname(),user.getPwd());
    }
}
